package com.soft.line.controller;


import com.soft.line.service.LoginService;
import com.soft.line.util.exception.CommonResult;
import com.soft.line.util.exception.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wu.xueqiao on 2020/5/8.
 * @version 0.1
 */
@Api(description = "登录相关接口")
@Slf4j
@RestController
@RequestMapping("/auth")
public class LoginController {

    @Autowired
    private LoginService loginService;


    @ApiOperation(value = "登录", notes = "登录系统")
    @ApiImplicitParams({
             @ApiImplicitParam(paramType = "query", name = "userame", value = "账号", required = false, dataType = "String"),
             @ApiImplicitParam(paramType = "query", name = "password", value = "密码", required = false, dataType = "String")
    })
    @PostMapping("/login")
    public CommonResult loginUserInfo(@RequestBody Map<String,String> map){
        return loginService.userLogin(map);
    }
    @ApiOperation(value = "登出", notes = "登出系统")
    @ApiImplicitParams({
    })
    @PostMapping("/logout")
    public CommonResult exitUser(){
        return loginService.loginOut();
    }

    @PostMapping("/userInfo")
    public CommonResult getUserInfo(){
        return CommonResult.success(loginService.getUserPermission());
    }

    @GetMapping("/test")
    public CommonResult getStr(){
        return CommonResult.success("abc");
    }

    @PostMapping("/getSupDep")
    public CommonResult getSupDep(@RequestBody Map<String,String> map){
        String depId= (String)map.get("depId");
        return CommonResult.success(loginService.getSupDep(depId));
    }
}


